/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cjava.system.util;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.cjava.system.dao.interfac.IStateDao;
import org.cjava.system.model.State;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

/**
 *
 * @author max
 */
public class Clazz {

    @Autowired
    @Qualifier("stateDao")
    IStateDao stateDao;
    /**
     * ESTADOS GLOBALES, REALIZA SELECT PARA TODOS
     * @param name
     * @param entity
     * @return 
     */
    public State STATE(String name, String entity) {
        String HQL = "select s.id as id, s.name as name, s.entityName as entityName"
                + " from State s where s.name='(name)' and s.entityName='(nameEntity)'";
        HQL = HQL.replace("(name)", name.toUpperCase());
        HQL = HQL.replace("(nameEntity)", entity);

        try {
            List<State> listState = stateDao.listHQL(HQL, State.class);
            if (listState.isEmpty()) {
                State state = new State();
                state.setName(name);
                state.setEntityName(entity);
                int idState = stateDao.save(state);
                state.setId(idState);
                return state;
            } else {
                return listState.get(0);
            }
        } catch (Exception ex) {
            Logger.getLogger(Clazz.class.getName()).log(Level.SEVERE, null, ex);
        }

        return null;
    }

    public static class _STATE {

        public static class _NAME {
            /**
             * ESTADO PARA MEETING (EVENTO)
             */
            public static String _MEETING_SOLO_SOCIOS = "EVENTO SOLO PARA SOCIOS";
            /**
             * ESTADO PARA MEETING (EVENTO)
             */
            public static String _MEETING_SOCIOS_Y_PERSONAS = "EVENTO PARA PÚBLICO EN GENERAL";
            public static String _MEETING_FINALIZAR_EVENTO = "EVENTO FINALIZADO";
            /**
             * ESTADO PARA MEETING (EVENTO)
             */
            public static String _FINALIZAR = "EVENTO FINALIZADO";
            
            public static String _BENEFIT_ACTIVO = "ACTIVO PARA SOCIOS";
            public static String _BENEFIT_FINALIZADO = "BENEFICO FINALIZADO";
            public static String _BUSINESS_ASSOCIATE_CARNET_PERDIDO = "CARNET PERDIDO";
            public static String _BUSINESS_ASSOCIATE_CARNET_NUEVO = "CARNET NUEVO";
            
        }

        public static class _ENTITY {
            /**
             * ESTIDAD MEETING (EVENTO)
             */
            public static String _Meeting = "Meeting";
            public static String _Benefit = "Benefit";
            public static String _BusinessAssociate = "BusinessAssociate";
        }
    }

    public static class _TYPE_SYSTEM_USER {
        public static String _ADMIN_CONFIG = "USUARIO DE SOPORTE";
        public static String _SOCIO = "USUARIO SOCIO";
        public static String _ADMIN_USER = "USUARIO DEL SISTEMA";
        public static String _EMPRESA = "USUARIO DE EMPRESA";
    }
    
    /**
     * Tipo de perfil que tiene.
     */
    public static class _TYPE_PROFILE {
        public static String _FRAMEWORK_JAVA = "FRAMEWORK JAVA";
        public static String _DATABASE = "BASE DE DATOS";
        public static String _TOOLS = "HERRAMIENTAS";
        public static String _CERTIFICATION = "CERTIFICACIONES";
        public static String _LANGUAGE = "LENGUAJE";
    }
    
    /**
     * REDONDEA EL NUMERO DE TIENE MAS DE UN DIGITO
     * @param number NUMERO EJM: 50.371346
     * @param digits NUMERO DE DIGITOS EJM:2
     * @return EL RESULTADO: 50.37
     */
    public static double ROUND(double number, int digits) {
        int cifras = (int) Math.pow(10, digits);
        return Math.rint(number * cifras) / cifras;
    }
}
